package org.dromara.quickswing.database.sqlite;

import cn.hutool.db.ds.simple.SimpleDataSource;
import org.dromara.quickswing.database.QSDbManager;
import org.dromara.quickswing.ui.app.QSPrefs;

import javax.sql.DataSource;
import java.io.File;
/**
 * @author Jin
 */
public class SqliteDbManager implements QSDbManager {
    private static final String DRIVER = "org.sqlite.JDBC";
    private static DataSource dataSource;


    public  void initialize(QSPrefs QSPrefs) {
        if (dataSource == null) {
            String dbUrl = "jdbc:sqlite:" + QSPrefs.getDataPath() + File.separator + QSPrefs.getDbFileName() + ";";
            dataSource = new SimpleDataSource(dbUrl, null, null, DRIVER);
        }
    }

    @Override
    public DataSource getDatasource() {
        return dataSource;
    }
}
